home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / clientuamglue.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.0 KB  |  146 lines

  1. // 
  2. // Apple Macintosh Developer Technical Support
  3. // Written by:  Vinnie Moscaritolo
  4. //
  5. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  6. //
  7. // You may incorporate this sample code into your applications without
  8. // restriction, though the sample code has been provided "AS IS" and the
  9. // responsibility for its operation is 100% yours.  However, what you are
  10. // not permitted to do is to redistribute the source as "DSC Sample Code"
  11. // after having made changes. If you're going to re-distribute the source,
  12. // we require that you make it clear in the source that the code was
  13. // descended from Apple Sample Code, but that you've made changes.
  14. // 
  15.  
  16.  
  17. //------------------------------------------------------------------------------------
  18. #pragma mark Includes
  19. //------------------------------------------------------------------------------------
  20. #include <stdio.h>
  21. #include <String.h>
  22. #include <Errors.h>
  23. #include <A4Stuff.h>
  24. #include <Dialogs.h>
  25. #include <Resources.h>
  26. #include <CodeFragments.h>
  27. #include <MixedMode.h>
  28. #include <RegisterFileLibs.h>
  29. #include "ClientUAM.h" 
  30.  
  31. // ---------------------------------------------------------------------------
  32. #pragma mark local Prototypes
  33. // ---------------------------------------------------------------------------
  34. typedef pascal     OSStatus (*UAMCallProcPtr) (UAMArgs *theArgs);
  35.  
  36.  
  37. pascal     OSStatus    main        (UAMArgs *theArgs);
  38. OSErr    MAKEFSSPECFROMREFNUM    (short theRefNum, FSSpec *theFileSpec);
  39.  
  40. UniversalProcPtr    mainAddr = nil;
  41. CFragConnectionID    connID = nil;
  42.  
  43. // ---------------------------------------------------------------------------
  44. pascal OSStatus main(UAMArgs *theArgs)
  45. // ---------------------------------------------------------------------------
  46. {
  47.     OSStatus                ErrNo = noErr;
  48.     Str255                    errorMessage;
  49.     SInt16                     itemHit;
  50.      
  51.     FSSpec                     theFileSpec;
  52.     ProcPtr                    codePtr;
  53.  
  54.       EnterCodeResource();
  55.  
  56. // first time through
  57.     if(mainAddr == nil) {
  58.      
  59.         ErrNo = MAKEFSSPECFROMREFNUM( CurResFile(), &theFileSpec);
  60.  
  61.         if (ErrNo != noErr){
  62.             DebugStr("\pError  Could't make fsspec , HUH\n");
  63.             goto Error;
  64.             }
  65.  
  66.         ErrNo = RegisterFileLibs (&theFileSpec );
  67.         if ((ErrNo != noErr ) && (ErrNo != cfragDupRegistrationErr))
  68.             {
  69.             DebugStr("\pError  Could't make RegisterFileLibs\n");
  70.             goto Error;
  71.             }
  72.  
  73.         
  74. // Activate the PGPUAM ppc module
  75.         ErrNo = GetSharedLibrary("\pPGPUAM.PPC", 
  76.                                         kPowerPCCFragArch, 
  77.                                         kReferenceCFrag, 
  78.                                         &connID, 
  79.                                         &(Ptr)codePtr, 
  80.                                         errorMessage);
  81.  
  82.         if (ErrNo != noErr){
  83.             DebugStr("\pError  Could't load PGPUAM\n");
  84.             goto Error;
  85.             }
  86.  
  87.         if (codePtr == nil) {
  88.             DebugStr("\pError PGPUAM mainAddr == nil\n");
  89.             CloseConnection(&connID);
  90.              ErrNo = -1; //kOutOfMemoryErr
  91.              goto Error;
  92.             }
  93.     
  94.         mainAddr  = NewRoutineDescriptorTrap(codePtr, kUAMCallProcInfo,kPowerPCISA);
  95.         }
  96.  
  97.     ErrNo = ((UAMCallProcPtr)mainAddr) (theArgs);
  98.     
  99.     if((mainAddr != nil) 
  100.         && (     (theArgs->command == kUAMClose)
  101.             ||  ((theArgs->command == kUAMOpen) && (ErrNo != noErr))))
  102.     {
  103.         DisposeRoutineDescriptor(mainAddr);
  104.         CloseConnection(&connID);
  105.         mainAddr = nil;
  106.         }
  107.      ExitCodeResource();
  108.      return ErrNo;
  109.  
  110. Error:
  111. // handle error
  112.      StandardAlert(kAlertStopAlert,"\pPGPUAM Failed to load",nil, nil , &itemHit);
  113.      ExitCodeResource();
  114.      return ErrNo;
  115. }
  116.  
  117.  
  118. /*
  119. ** MakeFSSpecFromRefNum - make an FSSpec from an open path's file
  120. **  reference number
  121. ** 
  122. */
  123.                                        
  124. OSErr    MAKEFSSPECFROMREFNUM(short theRefNum, FSSpec *theFileSpec)
  125. {
  126.     FCBPBRec    theFCBInfo;
  127.     OSErr        theError;
  128.                                        
  129.     /* Use PBGetFCBInfo to get the  relevant information */
  130.  
  131.      theFCBInfo.ioNamePtr = theFileSpec->name;
  132.     theFCBInfo.ioVRefNum = 0;
  133.     theFCBInfo.ioRefNum = theRefNum;
  134.     theFCBInfo.ioFCBIndx = 0;
  135.     theError = PBGetFCBInfoSync(&theFCBInfo);
  136.     if( theError == noErr ){
  137.         theFileSpec->vRefNum = theFCBInfo.ioFCBVRefNum;
  138.         theFileSpec->parID = theFCBInfo.ioFCBParID;
  139.     }
  140.                                            
  141.     return(theError);
  142.                                        
  143. }    /* MakeFSSpecFromRefNum */    
  144.  
  145.  
  146.